package com.gingko.duominuo.utils.compressor

import androidx.annotation.WorkerThread
import com.gingko.duominuo.utils.createOrExistsFile
import java.io.File
import java.io.IOException
import kotlin.jvm.Throws

/**
 * 描述：
 * -
 * 创建人：bsx
 * 创建时间：2017/12/21
 */
object Compressor {
    private var mLeastCompressSize = 100
    private val mPaths: List<String>? = null

    /**
     * do not compress when the origin image file size less than one value
     *
     * @param size the value of file size, unit KB, default 100K
     */
    fun ignoreBy(size: Int): Compressor {
        mLeastCompressSize = size
        return this
    }


    interface FileCallback {
        fun compressorSuccess(targetPath: String?)
    }

}

/**
 * start compress and return the mFile
 */
@WorkerThread
@Throws(IOException::class)
fun File.startCompress(targetFile: File): File {
    targetFile.createOrExistsFile()
    return Engine(this.absolutePath, targetFile).compress()
}